using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyState
{
    public Rigidbody2D rb;// 敌人刚体
    protected EnemyStateMachine stateMachine;// 敌人状态机
    protected Enemy enemyBase;// 敌人脚本

    protected bool triggerCalled;// 动画结束触发器
    private string animBoolName;// 动画名称

    protected float stateTimer;// 状态计时器

    public EnemyState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName)
    {
        this.enemyBase = _enemyBase;// 为状态初始化选择主体
        this.stateMachine = _stateMachine;// 为状态初始化选择状态机
        this.animBoolName = _animBoolName;// 为状态初始化选择动画条件
    }

    public virtual void Enter()
    {
        triggerCalled = false;// 设置动画未结束
        rb = enemyBase.rb;// 简写
        enemyBase.anim.SetBool(animBoolName, true);// 进入状态时选择动画

    }

    public virtual void Exit()
    {
        enemyBase.anim.SetBool(animBoolName, false);// 退出状态时取消动画
        enemyBase.AssignLastAnimName(animBoolName);// 保存死亡前动画名称
    }

    public virtual void Update()
    {
        stateTimer -= Time.deltaTime;// 计数器
    }

    public virtual void AnimationFinishTrigger()
    {
        triggerCalled = true;// 动画结束时触发
    }
}
